home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
polyvw31.lha
/
Polyview3.1
/
new
/
pvmsg.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-23
|
7KB
|
182 lines
/*****************************************************************************
* NCSA Polyview 3.0 *
* *
* Version 3 changes and additions by Marc Andreessen. *
* Version 2 by Brian Calvert. *
* *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* *
* This is BETA release software. As such it may contain software bugs and *
* exhibit inconsistencies. *
* *
* Please send bug reports to polyview@ncsa.uiuc.edu. *
* *
* Copyright (c) 1992 The Board of Trustees of the University of Illinois. *
* *
* Permission to use, copy, and modify this software and its *
* documentation for educational, research, and non-profit purposes is *
* hereby granted, provided that the above copyright notice, the original *
* authors names, and this permission notice appear in all such copies. *
* Any distribution of this software requires the explicit and written *
* authorization of the authors. *
* *
* The University of Illinois makes no representations about the *
* suitability of this software for any purpose. It is provided "as is" *
* without warranty of any kind. *
*****************************************************************************/
/* $Header: /usr3/people/gbourhis/pv3/new/RCS/pvmsg.c,v 1.1 92/09/18 10:55:26 marca Exp $ */
#ifdef RCSLOG
$Log: pvmsg.c,v $
* Revision 1.1 92/09/18 10:55:26 marca
* Initial revision
*
#endif
#include "pv.h"
/* OVERVIEW
"Messages" are an abstraction used to encapsulate inter-window
communication. Messages notify chosen sets of windows of a change in
the state of the program that could affect them. Typically this
occurs when the user performs some type of action, although messages
may also be triggered by timer events or changes in resource
availablity.
IMPLEMENTATION Messages are implemented via function pointers
associated with each window. These function pointers refer to
message-handling functions which parse the message and act on it, if
necessary. Each notify function is assumed to use the following list
of arguments:
int notify_fn(state_t * state, window_t * send_win,
window_t * recv_win, int message, ...)
The send_win is the window which originated the message (this is NULL
if irrelevant or if the system itself generated it). The recv_win is
the window whose notify_fn is being executed. The message value
determines how the notify function should interpret the arguments
which follow.
There is no reason the message-passing could not be implemented via
sockets or other inter-process or inter-machine connection media. */
/* broadcast message sends the message and its parameters to all of the */
/* windows. It sends the message to itself last of all, so that changes */
/* will wait until all windows have been notified. Returns ST_OKAY if no */
/* errors occur. */
int broadcast_msg(state_t * state, window_t * send_win, int msg, ...)
{
window_t *w;
va_list args;
/* Initlialize args to the beginning of the list. */
va_start(args, msg);
/* Pass the message to all other windows in the system. */
FOR_ALL_WINDOWS(state, w)
{
if (w != send_win)
{
/* If the notify function is NULL, it just means that */
/* window does not want messages. */
if (WIN_NOTIFY_FN(w) != NULL)
WIN_NOTIFY(w)(state, send_win, w, msg, args);
}
}
/* Send the message to the originating window. */
if ((send_win != NULL) && (WIN_NOTIFY_FN(send_win) != NULL))
WIN_NOTIFY(send_win)(state, send_win, send_win, msg, args);
va_end(args);
return ST_OKAY;
}
/* send message to id sends the message and its parameters to the window */
/* with the given id value. Returns ST_ERROR if there is no window with */
/* a matching id value, ST_OKAY otherwise. */
int send_msg_to_id(state_t * state, window_t * send_win, int id, int msg, ...)
{
window_t *w;
va_list args;
/* Pass the message to the window. */
w = find_window_by_id(state, id);
if (w != NULL)
{
va_start(args, msg);
send_msg_to_win(state, send_win, w, msg, args);
va_end(args);
return ST_OKAY;
}
else
{
return ST_ERROR;
}
}
/* send message to type sends the message and its parameters to all windows */
/* with the given type. Returns the number of windows which were notified, */
/* -1 if an error occurs. */
int send_msg_to_type(state_t * state, window_t * send_win, int type,
int msg, ...)
{
int matches;
window_t *w;
va_list args;
/* Initlialize args to the beginning of the list. */
va_start(args, msg);
/* Pass the message to every window in the system. */
matches = 0;
FOR_ALL_WINDOWS(state, w)
{
if (WIN_TYPE(w) == type)
{
matches++;
send_msg_to_win(state, send_win, w, msg, args);
}
}
va_end(args);
return matches;
}
/* send message to win sends the message and its parameters to the given */
/* window. Returns ST_ERROR if the window is illegal, ST_OKAY otherwise. */
int send_msg_to_win(state_t * state, window_t * send_win, window_t * recv_win,
int msg, ...)
{
va_list args;
/* If the window pointer is NULL, we have an error. */
if (recv_win == NULL)
{
return ST_ERROR;
}
else
{
/* If the notify function is NULL, it just means that this */
/* window does not want messages. */
if (WIN_NOTIFY_FN(recv_win) != NULL)
{
va_start(args, msg);
WIN_NOTIFY(recv_win)(state, send_win, recv_win, msg,
args);
va_end(args);
}
}
return ST_OKAY;
}